﻿using TextToHTML.Components;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TextToHTMLExtensionInterfaces;
using System;

namespace t_TextToHTML
{
    
    
    /// <summary>
    ///This is a test class for HTTPParserTest and is intended
    ///to contain all HTTPParserTest Unit Tests
    ///</summary>
    [TestClass()]
    public class HTTPParserTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for FindTextToReplace
        ///</summary>
        [TestMethod()]
        public void FindTextToReplaceTestNoHTTP()
        {
            HTTPParser target = new HTTPParser(); // TODO: Initialize to an appropriate value
            TextRun[] actual = target.FindTextToReplace("hi there");
            Assert.IsNotNull(actual, "Null return not allowed");
            Assert.AreEqual(0, actual.Length, "Should be no matched text runs");
        }

        /// <summary>
        ///A test for FindTextToReplace
        ///</summary>
        [TestMethod()]
        public void FindTextToReplaceTestOnlyHTTP()
        {
            HTTPParser target = new HTTPParser(); // TODO: Initialize to an appropriate value
            string url = "http://www.nytimes.net/dude.png";
            TextRun[] actual = target.FindTextToReplace(url);
            Assert.AreEqual(1, actual.Length, "Should be one matched text runs");
            TextRun r = actual[0];
            Assert.AreEqual(0, r.Start, "Start of http found not right");
            Assert.AreEqual(url.Length, r.Length, "Length of http found not right");
            Assert.AreEqual(typeof(Uri), r.whatItIs.GetType(), "Object type for http found not right");
            Uri uri = r.whatItIs as Uri;
            Assert.AreEqual(url, uri.AbsoluteUri, "URL found not right!");
        }

        /// <summary>
        ///A test for FindTextToReplace
        ///</summary>
        [TestMethod()]
        public void FindTextToReplaceTestHTTPAndText()
        {
            HTTPParser target = new HTTPParser(); // TODO: Initialize to an appropriate value
            string url = "http://www.nytimes.net/dude.png";
            TextRun[] actual = target.FindTextToReplace("Fork " + url + " it over");
            Assert.AreEqual(1, actual.Length, "Should be one matched text runs");
            TextRun r = actual[0];
            Assert.AreEqual(5, r.Start, "Start of http found not right");
            Assert.AreEqual(url.Length, r.Length, "Length of http found not right");
            Assert.AreEqual(typeof(Uri), r.whatItIs.GetType(), "Object type for http found not right");
            Uri uri = r.whatItIs as Uri;
            Assert.AreEqual(url, uri.AbsoluteUri, "URL found not right!");
        }
    }
}
